package com.carsa.blackberry.domain.dto;

import com.carsa.blackberry.util.XMLHandler;

/**
 * @author Nahuel Barrios.
 * @since 11/08/2010.
 * @version 1.0
 */
public class QueueMessageDTO {

    public static final String  XML_ELEMENT_MESSAGE            = "message";
    public static final String  XML_ELEMENT_PARAMETERS         = "parameters";
    private static final String XML_ELEMENT_WEB_SERVICE_NAME   = "webServiceName";
    private static final String XML_ELEMENT_WEB_SERVICE_METHOD = "webServiceMethod";

    private String              webServiceName;
    private String              webServiceMethod;
    private String              parameters;

    public QueueMessageDTO() {
	super();
    }

    /**
     * @param xmlSource
     *            El {@link String} en formato XML del cual se deben recuperar los atributos para setear el objeto this.
     */
    public QueueMessageDTO(String xmlSource) {
	super();
	this.initializeFromXML(xmlSource);
    }

    /**
     * @param xmlSource
     *            El {@link String} en formato XML del cual se deben recuperar los atributos para setear el objeto this.
     */
    public void initializeFromXML(String xmlSource) {
	XMLHandler xml = new XMLHandler(xmlSource);

	webServiceMethod = xml.getElementValue(XML_ELEMENT_WEB_SERVICE_METHOD);
	webServiceName = xml.getElementValue(XML_ELEMENT_WEB_SERVICE_NAME);
	parameters = xml.getElement(XML_ELEMENT_PARAMETERS);
    }

    public String toString() {
	return "QueueMessageDTO [ webServiceMethod=" + webServiceMethod + ", webServiceName=" + webServiceName
	        + ", parameters=" + parameters + "]";
    }

    /**
     * @return the webServiceName
     */
    public String getWebServiceName() {
	return webServiceName;
    }

    /**
     * @param webServiceName
     *            the webServiceName to set
     */
    public void setWebServiceName(String webServiceName) {
	this.webServiceName = webServiceName;
    }

    /**
     * @return the webServiceMethod
     */
    public String getWebServiceMethod() {
	return webServiceMethod;
    }

    /**
     * @param webServiceMethod
     *            the webServiceMethod to set
     */
    public void setWebServiceMethod(String webServiceMethod) {
	this.webServiceMethod = webServiceMethod;
    }

    /**
     * @return the parameters
     */
    public String getParameters() {
	return parameters;
    }

    /**
     * @param parameters
     *            the parameters to set
     */
    public void setParameters(String parameters) {
	this.parameters = parameters;
    }

    /**
     * @return Un {@link String} en formato XML conteniendo la informacion de esta cola de mensajes.
     */
    public String toXmlString() {
	XMLHandler xml = new XMLHandler(XML_ELEMENT_MESSAGE, null, null);
	xml.addElementAtRoot(XML_ELEMENT_WEB_SERVICE_NAME, null, this.webServiceName);
	xml.addElementAtRoot(XML_ELEMENT_WEB_SERVICE_METHOD, null, this.webServiceMethod);
	xml.addElementAtRoot(XML_ELEMENT_PARAMETERS, null, this.parameters);

	return xml.toString();
    }

}
